/*
 * Connect3View.java
 */

package connect3.team7.gui;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.table.DefaultTableModel;
import javax.swing.event.*;
import java.util.*;

import java.rmi.RemoteException;
import connect3.team7.util.*;
import connect3.team7.game.*;

/**
 * The application's main frame.
 */
public class Connect3View extends FrameView {

    public Connect3View(SingleFrameApplication app) {
        super(app);
        
        instance = this;

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = Connect3.getApplication().getMainFrame();
            aboutBox = new Connect3AboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        Connect3.getApplication().show(aboutBox);
    }
    
    @Action
    public void showClientSetup() {
        setupTabbedPane.setSelectedIndex(0);
        setupTabbedPane.setEnabledAt(0, true);
        setupTabbedPane.setEnabledAt(1, false);
        setupTabbedPane.setVisible(true);
        
    }
    
    @Action
    public void showHostSetup() {
        setupTabbedPane.setSelectedIndex(1);
        setupTabbedPane.setEnabledAt(0, false);
        setupTabbedPane.setEnabledAt(1, true);
        setupTabbedPane.setVisible(true);
    }
    
    // Utility methods - Kenny
    public static Connect3View getInstance() {
        return instance;
    }
    
    private String getTokenImagePath(String playerType) {
        String res = null;
        int selected = 0;
        
        if ("host".equals(playerType))
           selected = hostTokenColorComboBox.getSelectedIndex();
        else
           selected = clientTokenColorComboBox.getSelectedIndex();  
        
        
        switch (selected) {
            case 0: res = "images/green_token.GIF"; break;
            case 1: res = "images/blue_token.GIF"; break;
            case 2: res = "images/red_token.GIF"; break;
            case 3: res = "images/black_token.GIF"; break;
            case 4: res = "images/yellow_token.GIF"; break;
            case 5: res = "images/orange_token.GIF"; break;
        }
        
        return res;
    }
    
    public void updateGameboardGUI(Token token) {
        
        ImageIcon image = new ImageIcon(player.getTokenImage());
        gameboard_model.setValueAt(image, token.getX(), token.getY());
    }
    
    public void showActivePlayersList() {
        if (player.isHost()) {
            activePlayersList.setVisible(true);
        }
        
        DefaultListModel list_contents = new DefaultListModel();
        
        Enumeration<String> e = cc.getActivePlayers();
        
        while (e.hasMoreElements()) {
            list_contents.addElement(e.nextElement());
        }
        
        activePlayersList.setModel(list_contents);
        activePlayersList.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        setupFrame = new javax.swing.JInternalFrame();
        setupTabbedPane = new javax.swing.JTabbedPane();
        clientSetupPanel = new javax.swing.JPanel();
        hostListingPanel = new javax.swing.JPanel();
        hostListingPanel.setVisible(false);
        jScrollPane1 = new javax.swing.JScrollPane();
        hostList = new javax.swing.JList();
        hostListSeparator = new javax.swing.JSeparator();
        SelectAHostLabel = new javax.swing.JLabel();
        hostDetailsPanel = new javax.swing.JPanel();
        hostDetailsPanel.setVisible(false);
        NoOfPlayersLabel = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        NoOfPlayersTxtFld = new javax.swing.JTextField();
        timeLimitGetTxtFld = new javax.swing.JTextField();
        connectButton = new javax.swing.JButton();
        clientPlayerPanel = new javax.swing.JPanel();
        showHostsButton = new javax.swing.JButton();
        playerNameLabel = new javax.swing.JLabel();
        clientPlayerNameTxtFld = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        clientTokenColorComboBox = new javax.swing.JComboBox();
        hostSetupPanel = new javax.swing.JPanel();
        hostPlayerNameLbl = new javax.swing.JLabel();
        hostPlayerNameTxtFld = new javax.swing.JTextField();
        noOfPlayersLbl = new javax.swing.JLabel();
        noOfPlayersTxtFld = new javax.swing.JTextField();
        hostSettingsSeparator = new javax.swing.JSeparator();
        hostSettingsTitleLbl = new javax.swing.JLabel();
        timeLimitLbl = new javax.swing.JLabel();
        timeLimitTxtFld = new javax.swing.JTextField();
        boardDimLbl = new javax.swing.JLabel();
        widthLbl = new javax.swing.JLabel();
        heightLbl = new javax.swing.JLabel();
        widthTxtFld = new javax.swing.JTextField();
        heightTxtFld = new javax.swing.JTextField();
        connSettingsLbl = new javax.swing.JLabel();
        portLbl = new javax.swing.JLabel();
        portTxtFld = new javax.swing.JTextField();
        createGameButton = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        hostTokenColorComboBox = new javax.swing.JComboBox();
        host_client_pane = new javax.swing.JPanel();
        host_selection_rb = new javax.swing.JRadioButton();
        client_selection_rb = new javax.swing.JRadioButton();
        GameboardPanel = new javax.swing.JPanel();
        GameboardPanel.setVisible(false);
        jScrollPane2 = new javax.swing.JScrollPane();
        gameboardTable = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        activePlayersList = new javax.swing.JList();
        activePlayersList.setVisible(false);
        jLabel4 = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        host_client_rb_group = new javax.swing.ButtonGroup();

        mainPanel.setName("mainPanel"); // NOI18N

        setupFrame.setResizable(true);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(connect3.team7.gui.Connect3.class).getContext().getResourceMap(Connect3View.class);
        setupFrame.setTitle(resourceMap.getString("setupFrame.title")); // NOI18N
        setupFrame.setFrameIcon(resourceMap.getIcon("setupFrame.frameIcon")); // NOI18N
        setupFrame.setName("setupFrame"); // NOI18N
        setupFrame.setVisible(true);

        setupTabbedPane.setName("setupTabbedPane"); // NOI18N
        setupTabbedPane.setVisible(false);

        clientSetupPanel.setName("clientSetupPanel"); // NOI18N

        hostListingPanel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        hostListingPanel.setName("hostListingPanel"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        hostList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        hostList.setName("hostList"); // NOI18N
        hostList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                hostListValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(hostList);

        hostListSeparator.setForeground(resourceMap.getColor("hostListSeparator.foreground")); // NOI18N
        hostListSeparator.setName("hostListSeparator"); // NOI18N

        SelectAHostLabel.setFont(resourceMap.getFont("SelectAHostLabel.font")); // NOI18N
        SelectAHostLabel.setText(resourceMap.getString("SelectAHostLabel.text")); // NOI18N
        SelectAHostLabel.setName("SelectAHostLabel"); // NOI18N

        hostDetailsPanel.setName("hostDetailsPanel"); // NOI18N

        NoOfPlayersLabel.setLabelFor(NoOfPlayersTxtFld);
        NoOfPlayersLabel.setText(resourceMap.getString("NoOfPlayersLabel.text")); // NOI18N
        NoOfPlayersLabel.setName("NoOfPlayersLabel"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        NoOfPlayersTxtFld.setBackground(resourceMap.getColor("NoOfPlayersTxtFld.background")); // NOI18N
        NoOfPlayersTxtFld.setText(resourceMap.getString("NoOfPlayersTxtFld.text")); // NOI18N
        NoOfPlayersTxtFld.setDisabledTextColor(resourceMap.getColor("NoOfPlayersTxtFld.disabledTextColor")); // NOI18N
        NoOfPlayersTxtFld.setEnabled(false);
        NoOfPlayersTxtFld.setName("NoOfPlayersTxtFld"); // NOI18N

        timeLimitGetTxtFld.setBackground(resourceMap.getColor("timeLimitGetTxtFld.background")); // NOI18N
        timeLimitGetTxtFld.setDisabledTextColor(resourceMap.getColor("timeLimitGetTxtFld.disabledTextColor")); // NOI18N
        timeLimitGetTxtFld.setEnabled(false);
        timeLimitGetTxtFld.setName("timeLimitGetTxtFld"); // NOI18N

        javax.swing.GroupLayout hostDetailsPanelLayout = new javax.swing.GroupLayout(hostDetailsPanel);
        hostDetailsPanel.setLayout(hostDetailsPanelLayout);
        hostDetailsPanelLayout.setHorizontalGroup(
            hostDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(hostDetailsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(hostDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(NoOfPlayersLabel)
                    .addComponent(jLabel1))
                .addGap(27, 27, 27)
                .addGroup(hostDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(NoOfPlayersTxtFld)
                    .addComponent(timeLimitGetTxtFld, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE))
                .addGap(34, 34, 34))
        );
        hostDetailsPanelLayout.setVerticalGroup(
            hostDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(hostDetailsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(hostDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(NoOfPlayersLabel)
                    .addComponent(NoOfPlayersTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(hostDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(timeLimitGetTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        connectButton.setText(resourceMap.getString("connectButton.text")); // NOI18N
        connectButton.setEnabled(false);
        connectButton.setName("connectButton"); // NOI18N
        connectButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                connectButtonMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout hostListingPanelLayout = new javax.swing.GroupLayout(hostListingPanel);
        hostListingPanel.setLayout(hostListingPanelLayout);
        hostListingPanelLayout.setHorizontalGroup(
            hostListingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(hostListSeparator, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 622, Short.MAX_VALUE)
            .addGroup(hostListingPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(66, 66, 66)
                .addComponent(hostDetailsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(231, 231, 231))
            .addGroup(hostListingPanelLayout.createSequentialGroup()
                .addGap(50, 50, 50)
                .addComponent(connectButton)
                .addContainerGap(497, Short.MAX_VALUE))
            .addGroup(hostListingPanelLayout.createSequentialGroup()
                .addGap(266, 266, 266)
                .addComponent(SelectAHostLabel)
                .addContainerGap(277, Short.MAX_VALUE))
        );
        hostListingPanelLayout.setVerticalGroup(
            hostListingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(hostListingPanelLayout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addComponent(SelectAHostLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(hostListSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(hostListingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(hostDetailsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(connectButton)
                .addContainerGap(16, Short.MAX_VALUE))
        );

        clientPlayerPanel.setName("clientPlayerPanel"); // NOI18N

        showHostsButton.setText(resourceMap.getString("showHostsButton.text")); // NOI18N
        showHostsButton.setName("showHostsButton"); // NOI18N
        showHostsButton.setEnabled(false);
        showHostsButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                showHostsButtonMouseClicked(evt);
            }
        });

        playerNameLabel.setText(resourceMap.getString("playerNameLabel.text")); // NOI18N
        playerNameLabel.setName("playerNameLabel"); // NOI18N

        clientPlayerNameTxtFld.setText(resourceMap.getString("clientPlayerNameTxtFld.text")); // NOI18N
        clientPlayerNameTxtFld.setName("clientPlayerNameTxtFld"); // NOI18N
        clientPlayerNameTxtFld.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                clientPlayerNameTxtFldKeyTyped(evt);
            }
        });

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        clientTokenColorComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Green", "Blue", "Red", "Black", "Yellow", "Orange" }));
        clientTokenColorComboBox.setName("clientTokenColorComboBox"); // NOI18N

        javax.swing.GroupLayout clientPlayerPanelLayout = new javax.swing.GroupLayout(clientPlayerPanel);
        clientPlayerPanel.setLayout(clientPlayerPanelLayout);
        clientPlayerPanelLayout.setHorizontalGroup(
            clientPlayerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(clientPlayerPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(playerNameLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(clientPlayerNameTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(44, 44, 44)
                .addComponent(showHostsButton)
                .addGap(98, 98, 98)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(clientTokenColorComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(57, Short.MAX_VALUE))
        );
        clientPlayerPanelLayout.setVerticalGroup(
            clientPlayerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(clientPlayerPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(clientPlayerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(playerNameLabel)
                    .addComponent(clientPlayerNameTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(showHostsButton)
                    .addComponent(jLabel2)
                    .addComponent(clientTokenColorComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout clientSetupPanelLayout = new javax.swing.GroupLayout(clientSetupPanel);
        clientSetupPanel.setLayout(clientSetupPanelLayout);
        clientSetupPanelLayout.setHorizontalGroup(
            clientSetupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(clientSetupPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(clientSetupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(clientPlayerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(hostListingPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        clientSetupPanelLayout.setVerticalGroup(
            clientSetupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(clientSetupPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(clientPlayerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(34, 34, 34)
                .addComponent(hostListingPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        setupTabbedPane.addTab(resourceMap.getString("clientSetupPanel.TabConstraints.tabTitle"), clientSetupPanel); // NOI18N

        hostSetupPanel.setName("hostSetupPanel"); // NOI18N

        hostPlayerNameLbl.setText(resourceMap.getString("hostPlayerNameLbl.text")); // NOI18N
        hostPlayerNameLbl.setName("hostPlayerNameLbl"); // NOI18N

        hostPlayerNameTxtFld.setName("hostPlayerNameTxtFld"); // NOI18N

        noOfPlayersLbl.setText(resourceMap.getString("noOfPlayersLbl.text")); // NOI18N
        noOfPlayersLbl.setName("noOfPlayersLbl"); // NOI18N

        noOfPlayersTxtFld.setText(resourceMap.getString("noOfPlayersTxtFld.text")); // NOI18N
        noOfPlayersTxtFld.setName("noOfPlayersTxtFld"); // NOI18N

        hostSettingsSeparator.setForeground(resourceMap.getColor("hostSettingsSeparator.foreground")); // NOI18N
        hostSettingsSeparator.setName("hostSettingsSeparator"); // NOI18N

        hostSettingsTitleLbl.setFont(resourceMap.getFont("hostSettingsTitleLbl.font")); // NOI18N
        hostSettingsTitleLbl.setText(resourceMap.getString("hostSettingsTitleLbl.text")); // NOI18N
        hostSettingsTitleLbl.setName("hostSettingsTitleLbl"); // NOI18N

        timeLimitLbl.setText(resourceMap.getString("timeLimitLbl.text")); // NOI18N
        timeLimitLbl.setName("timeLimitLbl"); // NOI18N

        timeLimitTxtFld.setText(resourceMap.getString("timeLimitTxtFld.text")); // NOI18N
        timeLimitTxtFld.setName("timeLimitTxtFld"); // NOI18N

        boardDimLbl.setFont(resourceMap.getFont("boardDimLbl.font")); // NOI18N
        boardDimLbl.setText(resourceMap.getString("boardDimLbl.text")); // NOI18N
        boardDimLbl.setName("boardDimLbl"); // NOI18N

        widthLbl.setText(resourceMap.getString("widthLbl.text")); // NOI18N
        widthLbl.setName("widthLbl"); // NOI18N

        heightLbl.setText(resourceMap.getString("heightLbl.text")); // NOI18N
        heightLbl.setName("heightLbl"); // NOI18N

        widthTxtFld.setText(resourceMap.getString("widthTxtFld.text")); // NOI18N
        widthTxtFld.setName("widthTxtFld"); // NOI18N

        heightTxtFld.setName("heightTxtFld"); // NOI18N

        connSettingsLbl.setFont(resourceMap.getFont("connSettingsLbl.font")); // NOI18N
        connSettingsLbl.setText(resourceMap.getString("connSettingsLbl.text")); // NOI18N
        connSettingsLbl.setName("connSettingsLbl"); // NOI18N

        portLbl.setText(resourceMap.getString("portLbl.text")); // NOI18N
        portLbl.setName("portLbl"); // NOI18N

        portTxtFld.setName("portTxtFld"); // NOI18N

        createGameButton.setText(resourceMap.getString("createGameButton.text")); // NOI18N
        createGameButton.setName("createGameButton"); // NOI18N
        createGameButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                createGameButtonMouseClicked(evt);
            }
        });

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        hostTokenColorComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Green", "Blue", "Red", "Black", "Yellow", "Orange" }));
        hostTokenColorComboBox.setName("hostTokenColorComboBox"); // NOI18N

        javax.swing.GroupLayout hostSetupPanelLayout = new javax.swing.GroupLayout(hostSetupPanel);
        hostSetupPanel.setLayout(hostSetupPanelLayout);
        hostSetupPanelLayout.setHorizontalGroup(
            hostSetupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(hostSettingsSeparator, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 635, Short.MAX_VALUE)
            .addGroup(hostSetupPanelLayout.createSequentialGroup()
                .addGap(285, 285, 285)
                .addComponent(hostSettingsTitleLbl)
                .addContainerGap(269, Short.MAX_VALUE))
            .addGroup(hostSetupPanelLayout.createSequentialGroup()
                .addGap(113, 113, 113)
                .addGroup(hostSetupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(heightLbl)
                    .addComponent(widthLbl))
                .addContainerGap(487, Short.MAX_VALUE))
            .addGroup(hostSetupPanelLayout.createSequentialGroup()
                .addGap(93, 93, 93)
                .addGroup(hostSetupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(connSettingsLbl)
                    .addComponent(boardDimLbl)
                    .addGroup(hostSetupPanelLayout.createSequentialGroup()
                        .addGroup(hostSetupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(noOfPlayersLbl)
                            .addComponent(timeLimitLbl)
                            .addComponent(hostPlayerNameLbl))
                        .addGap(45, 45, 45)
                        .addGroup(hostSetupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(hostPlayerNameTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(hostSetupPanelLayout.createSequentialGroup()
                                .addGroup(hostSetupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(timeLimitTxtFld)
                                    .addComponent(noOfPlayersTxtFld, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE)
                                    .addComponent(widthTxtFld)
                                    .addComponent(heightTxtFld, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE)
                                    .addComponent(portTxtFld, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE)
                                    .addComponent(createGameButton))
                                .addGap(78, 78, 78)
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(hostTokenColorComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(67, Short.MAX_VALUE))
            .addGroup(hostSetupPanelLayout.createSequentialGroup()
                .addGap(114, 114, 114)
                .addComponent(portLbl)
                .addContainerGap(497, Short.MAX_VALUE))
        );
        hostSetupPanelLayout.setVerticalGroup(
            hostSetupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(hostSetupPanelLayout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addComponent(hostSettingsTitleLbl)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(hostSettingsSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(hostSetupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(hostSetupPanelLayout.createSequentialGroup()
                        .addGroup(hostSetupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(hostPlayerNameLbl)
                            .addComponent(hostPlayerNameTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(hostSetupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(noOfPlayersLbl)
                            .addComponent(noOfPlayersTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(hostSetupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(timeLimitLbl)
                            .addComponent(timeLimitTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(25, 25, 25)
                        .addComponent(boardDimLbl)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(hostSetupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(widthLbl)
                            .addComponent(widthTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(hostSetupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(heightLbl)
                            .addComponent(heightTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(hostSetupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(hostSetupPanelLayout.createSequentialGroup()
                                .addComponent(connSettingsLbl)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(portLbl))
                            .addComponent(portTxtFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(32, 32, 32)
                        .addComponent(createGameButton))
                    .addGroup(hostSetupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(hostTokenColorComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(72, Short.MAX_VALUE))
        );

        setupTabbedPane.addTab(resourceMap.getString("hostSetupPanel.TabConstraints.tabTitle"), hostSetupPanel); // NOI18N

        host_client_pane.setName("host_client_pane"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(connect3.team7.gui.Connect3.class).getContext().getActionMap(Connect3View.class, this);
        host_selection_rb.setAction(actionMap.get("showHostSetup")); // NOI18N
        host_client_rb_group.add(host_selection_rb);
        host_selection_rb.setText(resourceMap.getString("host_selection_rb.text")); // NOI18N
        host_selection_rb.setName("host_selection_rb"); // NOI18N

        client_selection_rb.setAction(actionMap.get("showClientSetup")); // NOI18N
        host_client_rb_group.add(client_selection_rb);
        client_selection_rb.setText(resourceMap.getString("client_selection_rb.text")); // NOI18N
        client_selection_rb.setName("client_selection_rb"); // NOI18N

        javax.swing.GroupLayout host_client_paneLayout = new javax.swing.GroupLayout(host_client_pane);
        host_client_pane.setLayout(host_client_paneLayout);
        host_client_paneLayout.setHorizontalGroup(
            host_client_paneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(host_client_paneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(host_selection_rb)
                .addGap(68, 68, 68)
                .addComponent(client_selection_rb)
                .addContainerGap())
        );
        host_client_paneLayout.setVerticalGroup(
            host_client_paneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(host_client_paneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(host_client_paneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(host_selection_rb)
                    .addComponent(client_selection_rb))
                .addContainerGap())
        );

        javax.swing.GroupLayout setupFrameLayout = new javax.swing.GroupLayout(setupFrame.getContentPane());
        setupFrame.getContentPane().setLayout(setupFrameLayout);
        setupFrameLayout.setHorizontalGroup(
            setupFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(setupFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(setupFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(setupFrameLayout.createSequentialGroup()
                        .addComponent(host_client_pane, javax.swing.GroupLayout.PREFERRED_SIZE, 579, Short.MAX_VALUE)
                        .addGap(392, 392, 392))
                    .addGroup(setupFrameLayout.createSequentialGroup()
                        .addComponent(setupTabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE, 640, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(331, Short.MAX_VALUE))))
        );
        setupFrameLayout.setVerticalGroup(
            setupFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(setupFrameLayout.createSequentialGroup()
                .addGap(55, 55, 55)
                .addComponent(host_client_pane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(setupTabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE, 409, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        setupTabbedPane.getAccessibleContext().setAccessibleName(resourceMap.getString("jTabbedPane1.AccessibleContext.accessibleName")); // NOI18N

        GameboardPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        GameboardPanel.setName("GameboardPanel"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N
        jScrollPane2.setPreferredSize(new java.awt.Dimension(800, 600));

        gameboardTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        gameboardTable.setName("gameboardTable"); // NOI18N
        gameboardTable.setRowHeight(47);
        gameboardTable.setRowSelectionAllowed(false);
        gameboardTable.setSurrendersFocusOnKeystroke(true);
        gameboardTable.setTableHeader(null);
        gameboardTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                gameboardTableMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(gameboardTable);
        javax.swing.table.TableColumn column = null;

        for (int i=0; i < gameboardTable.getColumnCount(); i++) {
            column = gameboardTable.getColumnModel().getColumn(i);
            column.setMinWidth(152);
        }

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        activePlayersList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        activePlayersList.setName("activePlayersList"); // NOI18N
        jScrollPane3.setViewportView(activePlayersList);

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        javax.swing.GroupLayout GameboardPanelLayout = new javax.swing.GroupLayout(GameboardPanel);
        GameboardPanel.setLayout(GameboardPanelLayout);
        GameboardPanelLayout.setHorizontalGroup(
            GameboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(GameboardPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 465, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 189, Short.MAX_VALUE)
                .addGroup(GameboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(19, 19, 19))
        );
        GameboardPanelLayout.setVerticalGroup(
            GameboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(GameboardPanelLayout.createSequentialGroup()
                .addGroup(GameboardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(GameboardPanelLayout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 347, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(GameboardPanelLayout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(83, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(setupFrame)
                .addGap(296, 296, 296))
            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(GameboardPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(setupFrame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(134, Short.MAX_VALUE))
            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(GameboardPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 1293, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 1119, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void showHostsButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_showHostsButtonMouseClicked
        available_hosts = ClientController.getAvailableHosts();
        Iterator<HostConnectionSettings> i = available_hosts.iterator();       
        
        DefaultListModel list_contents = new DefaultListModel();
        
        while (i.hasNext()) {
            list_contents.addElement(i.next().getHandle());
        }

        hostList.setModel(list_contents);
        
        hostListingPanel.setVisible(true);
    }//GEN-LAST:event_showHostsButtonMouseClicked

    private void clientPlayerNameTxtFldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_clientPlayerNameTxtFldKeyTyped
        showHostsButton.setEnabled(true);
}//GEN-LAST:event_clientPlayerNameTxtFldKeyTyped

    private void hostListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_hostListValueChanged
        HostConnectionSettings selected_host = available_hosts.get(hostList.getSelectedIndex());
        
        NoOfPlayersTxtFld.setText(selected_host.getPlayerSlots() + "/6");
        timeLimitGetTxtFld.setText("" + selected_host.getTimeLimit());
        
        hostDetailsPanel.setVisible(true);
        connectButton.setEnabled(true);
        
    }//GEN-LAST:event_hostListValueChanged

    private void createGameButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_createGameButtonMouseClicked
        /*
        // Network Code
        HostConnectionSettings hcs = new HostConnectionSettings();
        hcs.setIP(IPUtil.getHostIP());
        hcs.setHandle(hostPlayerNameTxtFld.getText());
        hcs.setPlayerSlots((new Integer(noOfPlayersTxtFld.getText())).intValue());
        hcs.setPort( (new Integer(portTxtFld.getText()).intValue()));
        hcs.setTimeLimit( (new Integer(timeLimitTxtFld.getText()).intValue()));
        
        hc = HostController.getInstance(hcs);
         */
        
        // GUI Code
        setupFrame.setVisible(false);
        
        // Setting up the Player object
        player = new Player(hostPlayerNameTxtFld.getText(), true);
        player.setTokenImage(getTokenImagePath("host"));
        
        // Setting up the GUI Gameboard as a JTable
        gameboard_model = new DefaultTableModel() {
             @Override public int getRowCount() { return Integer.parseInt(heightTxtFld.getText()); }
             @Override public int getColumnCount() { return Integer.parseInt(widthTxtFld.getText()); }
             @Override public boolean isCellEditable(int row, int column) { return false; }
             @Override public Class<ImageIcon> getColumnClass(int columnIndex) { return ImageIcon.class; }

        };
        gameboardTable.setModel(gameboard_model);
        GameboardPanel.setVisible(true);
        
       
        
    }//GEN-LAST:event_createGameButtonMouseClicked

    private void connectButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_connectButtonMouseClicked
        // GUI Code
        setupFrame.setVisible(false);
        
        player = new Player(clientPlayerNameTxtFld.getText(), false);
        player.setTokenImage(getTokenImagePath("client"));
        
        HostConnectionSettings selected_host = available_hosts.get(hostList.getSelectedIndex());
        
        cc = ClientController.getInstance();
        
        try {
            cc.retrieveRemoteHost(selected_host);
            cc.join(player);
        } catch (RemoteException ex) {
            ex.printStackTrace();
        }
       
        
        // Setting up the GUI Gameboard as a JTable
        gameboard_model = new DefaultTableModel() {
             @Override public int getRowCount() { return Integer.parseInt(heightTxtFld.getText()); }
             @Override public int getColumnCount() { return Integer.parseInt(widthTxtFld.getText()); }
             @Override public boolean isCellEditable(int row, int column) { return false; }
             @Override public Class<ImageIcon> getColumnClass(int columnIndex) { return ImageIcon.class; }

        };
        gameboardTable.setModel(gameboard_model);
        GameboardPanel.setVisible(true);
        
        
    }//GEN-LAST:event_connectButtonMouseClicked

    private void gameboardTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gameboardTableMouseClicked
        /*
        //generate the token from the Player object
        Token token = player.genToken(jTable1.getSelectedColumn());
        boolean ret = gameboard.makeMove(t);
        
        //update the local gameboard object
        if (ret) {
            updateGameboardGUI(token);
        } else {
            invalid move pop-up goes here!
        }
         * 
         */
            
        ImageIcon image = new ImageIcon(player.getTokenImage());
        gameboard_model.setValueAt(image, gameboardTable.getSelectedRow(), gameboardTable.getSelectedColumn());
        
        // sync remote gameboards
}//GEN-LAST:event_gameboardTableMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel GameboardPanel;
    private javax.swing.JLabel NoOfPlayersLabel;
    private javax.swing.JTextField NoOfPlayersTxtFld;
    private javax.swing.JLabel SelectAHostLabel;
    private javax.swing.JList activePlayersList;
    private javax.swing.JLabel boardDimLbl;
    private javax.swing.JTextField clientPlayerNameTxtFld;
    private javax.swing.JPanel clientPlayerPanel;
    private javax.swing.JPanel clientSetupPanel;
    private javax.swing.JComboBox clientTokenColorComboBox;
    private javax.swing.JRadioButton client_selection_rb;
    private javax.swing.JLabel connSettingsLbl;
    private javax.swing.JButton connectButton;
    private javax.swing.JButton createGameButton;
    private javax.swing.JTable gameboardTable;
    private javax.swing.JLabel heightLbl;
    private javax.swing.JTextField heightTxtFld;
    private javax.swing.JPanel hostDetailsPanel;
    private javax.swing.JList hostList;
    private javax.swing.JSeparator hostListSeparator;
    private javax.swing.JPanel hostListingPanel;
    private javax.swing.JLabel hostPlayerNameLbl;
    private javax.swing.JTextField hostPlayerNameTxtFld;
    private javax.swing.JSeparator hostSettingsSeparator;
    private javax.swing.JLabel hostSettingsTitleLbl;
    private javax.swing.JPanel hostSetupPanel;
    private javax.swing.JComboBox hostTokenColorComboBox;
    private javax.swing.JPanel host_client_pane;
    private javax.swing.ButtonGroup host_client_rb_group;
    private javax.swing.JRadioButton host_selection_rb;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JLabel noOfPlayersLbl;
    private javax.swing.JTextField noOfPlayersTxtFld;
    private javax.swing.JLabel playerNameLabel;
    private javax.swing.JLabel portLbl;
    private javax.swing.JTextField portTxtFld;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JInternalFrame setupFrame;
    private javax.swing.JTabbedPane setupTabbedPane;
    private javax.swing.JButton showHostsButton;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JTextField timeLimitGetTxtFld;
    private javax.swing.JLabel timeLimitLbl;
    private javax.swing.JTextField timeLimitTxtFld;
    private javax.swing.JLabel widthLbl;
    private javax.swing.JTextField widthTxtFld;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    
    private static Connect3View instance;

    private JDialog aboutBox;
    
    // networking variables
    private ArrayList<HostConnectionSettings> available_hosts;
    private ClientController cc;
    private HostController hc;
    
    // player stuff
    Player player;
    
    // JTable model for gameboard
    DefaultTableModel gameboard_model;
}
